
cc.Class({
    extends: require('GameUI'),

    properties: {
        maskGroup:cc.Node,
        finger:cc.Node,
        tips:cc.Label,
        back:cc.Node
    },

    onLoad () {
        this.count=0
        this.leftNode = this.maskGroup.getChildByName('left');
        this.upNode = this.maskGroup.getChildByName('up');
        this.downNode = this.maskGroup.getChildByName('down');
        this.rightNode = this.maskGroup.getChildByName('right');

        this.frameNode = this.finger.getChildByName('frame');
        this.frameNode.on(cc.Node.EventType.TOUCH_START,this.onTouch,this);
        this.back.on(cc.Node.EventType.TOUCH_END,this.out,this);
        global.Event.on('NOTICE',this.notice.bind(this),this)
    },

    onDestroy(){
        global.Event.off('NOTICE')
    },
 
    out(){
        global.Data.isFirst=false
        global.UIMgr.popUI();
        global.GameLoop.enterSelectPlane();
    },

    start(){
        this.gameUI=global.GameLoop.GameMgr.s_gameUI.node;

        // this.otherPlane=cc.find('bottom/skill1/otherPlane',this.gameUI);
        this.bomb=cc.find('bottom/skill1/pow',this.gameUI);
        this.emp=cc.find('bottom/emp',this.gameUI);
        this.energy=cc.find('Energy',this.gameUI);
        this.player=global.GameLoop.GameMgr.o_player.node;
        // this.prop = global.GameLoop.GameMgr.no_PropsLayer;
        
        this.setMaskNode(this.player);
        this.setLabel(this.count)
    },

    setMaskNode(node) {
        global.GameLoop.GameMgr.pauseGame();
        var start = node.convertToWorldSpaceAR(cc.v2(-node.width / 2, -node.height / 2));
        this.leftNode.width = start.x;
        this.leftNode.height = node.height;
        this.leftNode.y = start.y;
        this.upNode.height = cc.winSize.height - (start.y + node.height);
        this.downNode.height = start.y;
        this.rightNode.y = start.y;
        this.rightNode.height = node.height;
        this.rightNode.width = cc.winSize.width - (start.x + node.width);

        this.finger.x=start.x-cc.winSize.width/2-40
        this.finger.y=start.y-cc.winSize.height/2-40;
        this.frameNode.width=node.width+80;
        this.frameNode.height=node.height+80;
    },

    onTouch(){
        this.maskGroup.active=false;
        this.finger.active=false;
        this.tips.node.parent.active=false;
        global.GameLoop.GameMgr.resumeGame()
        if(this.count==2){
            this.onClickEmp()
        }else if(this.count==3){
            this.onClickSuperBomb()
        }else if(this.count==5){
            // this.onClickWingMan()
        }
        this.count++;
        // if(this.count==5){
        //     this.scheduleOnce(()=>{
        //         this.showMask()
        //         this.setMaskNode(this.otherPlane);
        //         this.setLabel(this.count)
        //     },3)
        // }
    },

    showMask(){
        this.maskGroup.active=true;
        this.finger.active=true;
        this.tips.node.parent.active=true;
    },

    setLabel(count){
        this.arr=['点击飞机即可移动飞机','拾取闪电升级能量槽来提升武器','使用护盾后敌机不能击中自己','点击必杀可以释放飞机大招','好了，准备boss吧。不要让自己的中心被打到就不会受伤了','打不过？赶紧召唤同伴吧！']
        this.tips.string=this.arr[count]
    },

    notice(data){
        // this.setMaskNode(global.GameLoop.GameMgr.s_gameUI.bomb.node.parent)
        if(this.count==1 && data.type=='0'){
            this.showMask()
            this.setMaskNode(this.energy);
            this.setLabel(this.count)
        }else if(this.count==2 && data.type=='1'){
            this.showMask()
            this.setMaskNode(this.emp);
            this.setLabel(this.count)
        }else if(this.count==3 && data.type=='2'){
            this.showMask()
            this.setMaskNode(this.bomb);
            this.setLabel(this.count)
        }else if(this.count==4 && data.type=='3'){
            this.showMask()
            this.setMaskNode(this.player);
            this.setLabel(this.count)
        }
    },
    // update (dt) {},
});
